﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.App.Api.Read.Application.Command.Fram;
using Traceability.App.Api.Read.Application.Command.FramCompany;
using Traceability.App.Api.Read.Application.Command.Health;
using Traceability.App.Api.Read.Application.Command.Kill;
using Traceability.App.Api.Read.Application.Command.KillCompany;
using Traceability.App.Api.Read.Application.Command.Trace;
using Traceability.App.Api.Read.DTO;
using Traceability.App.Domain;
using Traceability.App.Domain.养殖基本信息表;
using Traceability.App.Domain.屠宰信息表;
using Traceability.App.Domain.新文件夹;
using Traceability.App.ErrorCode;

namespace Traceability.App.Api.Read.Controllers
{
    /// <summary>
    /// 溯源
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TraceabilityController : ControllerBase
    {
        private readonly IMediator mediator;

        public TraceabilityController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增溯源信息  更改
        /// </summary> 
        /// <param name="request">参数</param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> CreateTrac(TraceabilityCreateCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 查询商品信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Task<ApiResult<List<ShopModel>>> GetShop([FromQuery]GetShopCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
       /// <summary>
       /// 显示溯源信息
       /// </summary>
       /// <param name="request"></param>
       /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<TranceDTO>> GetTracea([FromQuery]GetTraceaCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 删除保健信息11111111
        /// 删除溯源信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<int>> Del([FromQuery]DelCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPost]
        /// <summary>
        /// 反填5555555
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Task<ApiResult<TraceabilityModel>> FantTrace(FantCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> UpdateTrace(UpdateCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPost]
        public async Task<ApiResult<string>> UploadFile(IFormFile file)
        {
            try
            {
                var res = new ApiResult<string>();
                string savefile = Directory.GetCurrentDirectory() + @"/wwwroot/img"+file.FileName;
                using(FileStream fs=new FileStream(savefile, FileMode.Create))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
                var url = ("http://localhost:5090/" + file.FileName);

                return new ApiResult<string>()
                {
                    Code = ApiEnum.Ok, Message = "图片上传成功",Data= "http://localhost:5090/img"+file.FileName
                };
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 批量删除溯源信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public  Task<ApiResult<int>> PiDel([FromQuery]PiDelCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 详情溯源信息7777
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<SuYuanDetailDTO>> SuYuanDetail([FromQuery]SuYuanDetailCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
       /// <summary>
       /// 养殖详情
       /// </summary>
       /// <param name="request"></param>
       /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<FarmModel>> FramDetail([FromQuery] FramCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 养殖新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> CreateFram(CreateFramCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 养殖修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> UpdateFram(UpdateFramCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 保健添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> HealthCreate(HealthCreateCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 保健删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
       
        public Task<ApiResult<int>> HealthDel([FromQuery]HealthDelCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 保健修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> HealthUpdate(HealthUpdateCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 保健显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<HealthModel>>> HealthShow([FromQuery]HealthShowCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 养殖企业添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> CreateCompany(CreateCompanyCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 养殖企业显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<FarmCompanyModel>> GetComang([FromQuery]GetComangCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 养殖企业修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> UpdateCompany(UpdateCompanyCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 屠宰新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> KillCreate(KillCreateCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 屠宰修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> KillUpdate(KillUpdateCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 屠宰显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<KillInformationModel>> KillGet([FromQuery]KillGetCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 屠宰企业添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> KillCompany(KillCompanyCommand request)
        {
            //异常处理
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
